package com.it2297.renderer;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.it2297.model.Comment;
import com.it2297.model.User;

public class commentCellRenderer extends JLabel implements TableCellRenderer {
	private Comment comment;
	private User user;
	public commentCellRenderer() {
		setOpaque(true);
		setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
		setVerticalTextPosition(JLabel.TOP);
		setIconTextGap(10);
	}
	
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object object,
			boolean isSelected, boolean hasFocus, int row, int column) {
		comment = (Comment) object;
		switch (column) {
		case 0:
			user = new User();
			String name = user.getUser(comment.getUserId()).getName();
			
			setIcon(null);
			setText("<html><strong> User Name: </strong><br/>"
					+ name + "</html>");
			break;
		case 1:
			setIcon(null);
			setText("<html><strong> " + comment.getMessage()
					+ "<br><br>" + comment.getDateCreate() + "</html>");
			break;
		}

		if (row % 2 == 0) {
			setBackground(Color.WHITE);
		} else {
			setBackground(new Color(240, 240, 240));
		}

		setForeground(Color.BLACK);
		return this;
	}
	
}
